<?php

namespace App\Http\Controllers\Reservation;

use App\Http\Controllers\ApiController;
use App\Models\Reservation\Reservation;
use App\Models\Reservation\Role;
use App\Models\Reservation\Schedule;
use App\Project\Reserve\Reserve;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;

class StatisticsController extends ApiController
{
    /**
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function situation(Request $request)
    {
        $time = $request->input('time') ?: Carbon::now()->toDateString();

        $reserve = new Reserve(\Auth::user());

        $data = $reserve->situation($time)->get();

        return $this->response($data);
    }

    /**
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function visit(Request $request)
    {
        $input = $request->input();
        $week = [$input['start_time'], $input['end_time']];

        $reserve = new Reserve(\Auth::user());

        $visit = $reserve->visit($week);

        return $this->response($visit);
    }
}
